

from flask import jsonify,request
from main.utils import SWJsonify
from sqlalchemy import desc

from main.public.models import ProductHistory,DetailList
from main.user.models import User

from flask_login_multi import current_user,login_required

from .views import bp


@bp.route('/api/get_my_miner',methods=['GET'])
@login_required
def get_my_miner():
    """获取个人的矿机记录"""
    history = ProductHistory.query.filter_by(user_id=current_user.id).all()
    return SWJsonify({'result':history})


@bp.route('/api/get_my_promote',methods=['GET'])
@login_required
def get_my_promote():
    """获取个人推广记录"""
    user = User.query.filter_by(reid=current_user.id).all()
    return SWJsonify({'result':user})


@bp.route('/api/get_my_details',methods=['GET'])
@login_required
def get_my_details():
    """获取个人详细收支记录"""
    details = DetailList.query.filter_by(user_id=current_user.id).order_by(desc(DetailList.id)).all()
    return SWJsonify({'result':details})


